﻿using D.B.Data.API.Applications.Command.MenusCommand;
using D.B.Data.Domain;
using D.B.Data.ErrorCode;
using D.B.Data.Infrastructuse;
using MediatR;

namespace D.B.Data.API.Applications.CommandHandler.MenusCommandHandler
{
    public class QueryMenusLIstCommandHandler : IRequestHandler<QueryMenusLIstCommand, APIResult<int>>
    {
        private readonly IBaseRepository<MenusModel> baseRepository;

        public QueryMenusLIstCommandHandler(IBaseRepository<MenusModel> baseRepository)
        {
            this.baseRepository = baseRepository;
        }

        public Task<APIResult<int>> Handle(QueryMenusLIstCommand request, CancellationToken cancellationToken)
        {
            APIResult<int> result = new APIResult<int>();
            var res= baseRepository.GetAll().Where(s=>s.Pid==request.Id&&!s.IsDel).ToList();
            if(res.Count()>0)
            {
                result.Code=EnumCode.Ok;
                result.Msg = "有子集";
                result.Data = 1;
               
            }
            else
            {
                result.Code = EnumCode.Ok;
                result.Msg = "没子集";
                result.Data = 1;
                
            }

            return Task.FromResult(result);
        }
    }
}
